﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework;
using System.Xml.Serialization;
namespace Alex_s_Dream_The_Toy_World
{
    public class Save
    {
        [Serializable]
        public struct SaveGameData
        {
            public string PlayerName;
            public string screenSize;
            public string languages;
            public string Sound;
        }
        public void DoSaveGame(string name,string size,string languages,string sound)
        {
            // Create the data to save.
            SaveGameData data = new SaveGameData();
            data.PlayerName = name;
            data.screenSize = size;
            data.languages = languages;
            data.Sound = sound;

            // Get the path of the save game.
            string filename = Path.Combine("Content/Menu/", "savegame.xml");

            // Open the file, creating it if necessary.
            FileStream stream = File.Open(filename, FileMode.OpenOrCreate);

            // Convert the object to XML data and put it in the stream.
            XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
            serializer.Serialize(stream, data);

            // Close the file.
            stream.Close();
        }
        public void DoLoadGame(string name, string size, string languages, string sound)
        {
            // Get the path of the save game.
            string filename = Path.Combine("Content/Menu/", "savegame.xml");

            // Check to see whether the save exists.
            if (!File.Exists(filename))
                // Notify the user there is no save.
                return;

            // Open the file.
            FileStream stream = File.Open(filename, FileMode.OpenOrCreate,
                FileAccess.Read);

            // Read the data from the file.
            XmlSerializer serializer = new XmlSerializer(typeof(SaveGameData));
            SaveGameData data = (SaveGameData)serializer.Deserialize(stream);

            // Close the file.
            stream.Close();

            name = data.PlayerName;
            size = data.screenSize;
            languages = data.languages;
            sound = data.Sound;
        }
    }
}
